from typing import List


class Solution:
    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:
        # 统计 第 i 个字符 是否 以元音开头和结束
        def f(i):
            if words[i][0] in s and words[i][-1] in s:
                return 1
            return 0

        s = {'a', 'e', 'i', 'o', 'u'}
        # 构建前缀和： 前i个字符 有多少个以符合条件的
        pre = [0] * (len(words) + 1)
        for i in range(len(words)):
            pre[i + 1] = pre[i] + f(i)
        ans = []
        for left, right in queries:
            ans.append(pre[right + 1] - pre[left])
        return ans
